<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title>系统日志</title>
    <script src="../../../static/kaige/js/szload.js"></script>
    <style>
        .layui-table-tool-temp .tsinput {
            padding-right: 10px;
        }
    </style>
</head>

<body>
    <div class="kaige-body layui-form" style="margin-top: 0;">
        <table class="layui-hide" id="kaigeTable" lay-filter="kaigeTable" lay-size="sm"></table>
        <input type="hidden" name="keywordsCache" value="{}" />
    </div>
    <script>
        load_init_js(function () {
            layui.config({
                base: szoapcpath + '/static/kaige/layuiextend/'
            }).use(['form', 'layer',  'laydate', 'table', 'kaige'], function (form, layer,laydate, table, kaige) {

                kaige.table({
                    elem: '#kaigeTable',
                    title: '日志数据表',
                    url: "/sys.log/index",
                    id: 'kaigeTable',
                    toolbar: '#dtoolbar',
                    cols: [[
                        { type: 'checkbox', fixed: 'left' },
                        { field: 'id', title: 'ID', width: 70, hide: true },
                        { field: 'un', title: '操作人', width: 130 },
                        { field: 'node', title: '节点', width: 280, hide: true },
                        { field: 'ip', title: 'IP', width: 150 },
                        {
                            field: 'ip_addr', title: '地址', width: 300, templet: function (d) {
                                return d.ip_addr ? d.ip_addr.region   : '未知';
                            }
                        },
                        {
                            field: 'fname', title: '名称', width: 220, templet: function (d) {
                                return (d.fname ? d.fname : '') + '(' + d.action + ')';
                            }
                        },
                        { field: 'action', title: '行为', width: 130, hide: true },
                        { field: 'content', title: '操作内容' },
                        { field: 'create_time', width: 170, title: '操作时间' }
                    ]],
                    done: function (res, curr, count) {
                        //搜索框--回车提交
                        $("input[name=search_content],input[name=search_ip],input[name=search_username]").on('keyup', function (e) {
                            if (event.keyCode == 13) {
                                $("#btn-search").trigger("click");
                            }
                        });

                        //给筛选表单赋值
                        form.val("searchform", {
                            "search_ip": getkeywords('search_ip'),
                            "search_username": getkeywords('search_username'),
                            "search_content": getkeywords('search_content'),
                            "search_date": getkeywords('search_date')
                        });
                        //日期范围选择
                        laydate.render({
                            elem: '#search_date'
                            , range: '～'
                        });
                        form.render();
                    }
                });

                //列表-监听表头工具栏事件dtoolbar
                table.on('toolbar(kaigeTable)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'btn-del':
                            btn_del(checkStatus);
                            break;
                        case 'btn-search':
                            btnsearch();
                            break;
                    }
                });

                //搜索(筛选)
                function btnsearch() {
                    savekeywords('search_ip', $("input[name=search_ip]").val());
                    savekeywords('search_username', $("input[name=search_username]").val());
                    savekeywords('search_content', $("input[name=search_content]").val());
                    savekeywords('search_date', $("input[name=search_date]").val());
                    reload_sxtable({ type: 2 });
                }

                //执行筛选,重载表格
                function reload_sxtable(opt) {
                    if (opt && JSON.stringify(opt.where) == "{}" && opt.type === 1) {
                        layer.msg('当前没有筛选条件！'); return;
                    }
                    if (opt.type === 2) {
                        opt.where = {};
                        opt.where = getsearchform();
                    }
                    setTimeout(function () {
                        table.reload('kaigeTable', {
                            height: 'full-30',
                            page: { curr: 1 },
                            where: opt.where
                        });
                    }, 300);
                }

                //获取筛选表单
                function getsearchform() {
                    var gfv = {};
                    var key = ['search_ip', 'search_username', 'search_content', 'search_date'];
                    $.each(key, function (index, item) {
                        if(getkeywords(item)){
                            gfv[item] =  encodeURIComponent(getkeywords(item));
                        }
                    });
                    gfv.rnd = Math.random();
                    return gfv;
                }
                //删除
                function btn_del(d) {
                    kaige.del({
                        url: "/sys.log/del",
                        data: d.data,
                        tablelayid: 'kaigeTable',
                    });
                }
            });
        });
    </script>
    <script type="text/html" id="dtoolbar">
        <div class="layui-form" lay-filter="searchform">
            <div class="layui-inline">
                <input type="text" class="layui-input tsinput" name="search_ip" placeholder="ip" style="width:120px" />
            </div>
            <div class="layui-inline">
                <input type="text" class="layui-input tsinput" name="search_username" placeholder="操作人" style="width:120px" />
            </div>
            <div class="layui-inline">
                <input type="text" class="layui-input tsinput" name="search_content" placeholder="操作内容" style="width:160px" />
            </div>
            <div class="layui-inline">
                <input type="text" class="layui-input tsinput" name="search_date" id="search_date" placeholder="时间" style="width:200px" />
            </div>
            <div class="layui-inline">
                <button class="dsbutton" lay-event="btn-search" id="btn-search" title="筛选"><i class="layui-icon layui-icon-search"></i></button>
            </div>
            <div class="layui-btn-group">
                <button class="layui-btn layui-btn-sm" lay-event="btn-del"><i class="fa fa-trash"></i> 删除</button>
            </div>
        </div>
    </script>
</body>

</html>